package com.rongma.waterdrop.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间处理的工具类
 * Created by RongMa on 16/5/31.
 */
public class TimeUtils
{
    private static final String SHORT_TIME_FORMAT = "HH:mm:ss";
    private static final String LONG_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    private static final String DATE_FORMAT = "yyyy-MM-dd";

    /**
     * 将long类型数据转换为字符串: HH:mm:ss
     * @param time
     * @return
     */
    public static String getTimeByNumber(long time) throws IllegalAccessException {
        int hour = (int) Arith.div(time,3600,5);
        int minute = Arith.divAndRemainder(Arith.div(time,60,5),60);
        int second = Arith.divAndRemainder(time,60);
        String hourText = timeNumToText(hour);
        String minuteText = timeNumToText(minute);
        String secondText = timeNumToText(second);
        return hourText+":"+minuteText+":"+secondText;
    }

    private static String timeNumToText(int minute) {
        if(minute >= 10)
        {
            return Integer.toString(minute);
        }
        else
        {
            return "0"+minute;
        }
    }

    /**
     * 获取当前日期 yyyy-MM-dd
     * @return
     */
    public static String getDate()
    {
        SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
        Date date = new Date(System.currentTimeMillis());
        String dateText = format.format(date);
        return dateText;
    }
}
